using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TouchEnmeyEvent : MonoBehaviour
{
    public CharacterDatas_SO CharacterData_SO { get; set; } // 攻击参数（伤害、范围等）
    private IAttacker iAttacker; // 挂载时赋值：谁的武器

    void Awake()
    {
        iAttacker = GetComponentInParent<IAttacker>();
    }

    private void OnTriggerStay2D(Collider2D other)
    {
        if (other.gameObject.tag == "enemy")
        {

            // 可选：过滤自己/同阵营
            if (other.transform.IsChildOf(iAttacker.OwnerObject.transform)) return;
            var otherAtk = other.GetComponentInParent<IAttacker>();
            if (otherAtk != null && otherAtk.TeamId == iAttacker.TeamId) return;

            var dmg = transform.parent.GetComponentInParent<IDamageable>();
            if (dmg != null)
            {
                int amount = CharacterData_SO ? CharacterData_SO.attack : iAttacker.AttackPower;
                dmg.TakeDamage(amount, iAttacker.OwnerObject);
            }
        }

    }
}
